package com.tri.framework;

import android.graphics.Canvas;
import android.view.SurfaceHolder;

public class GameViewThread extends Thread
{
	private SurfaceHolder m_surfaceHolder;
	private GameView m_gameView;
	
	private boolean m_run = false;
	
	public GameViewThread(SurfaceHolder surfaceHolder, GameView gameview)
	{
		m_surfaceHolder = surfaceHolder;
		m_gameView = gameview;
	}

	public void setRunning(boolean run)
	{
		m_run = run;
	}
	
	public void run()
	{
		Canvas c;
		while(m_run)
		{
			c = null;
			try
			{
				m_gameView.update();
				c = m_surfaceHolder.lockCanvas(null);
				synchronized (m_surfaceHolder) {
					m_gameView.onDraw(c);
				}
			}
			finally
			{
				if(c != null)
				{
					m_surfaceHolder.unlockCanvasAndPost(c);
				}
			}
		}
	}
}
